*****************
* Preparations: *
*****************

	clear all
	set seed 123
	set obs 100000 // Set number of observations
	global path "Q:\SSB_skatt_boligomsetning\Deposits\do_files\replication kit" // path 

	
******************************************************
* Generating household and relationship identifiers: *
******************************************************

	gen hhid = round(runiform()*1000) + 1 // Each observation is a unique household for simplicity
	gen bankid = round(runiform()*10) + 1 // Randomly assign bank IDs from 1 to 10
	expand 14 
	egen relid = group(hhid bankid)
	bysort relid: gen year = _n 
	keep if year < 15
	gen muniid = round(runiform()*10) + 1 // Randomly assign municipality IDs from 1 to 10
	gen salaryquarter = round(runiform()*4) + 1 // Randomly assign salary quarter IDs from 1 to 4
	gen educ = round(runiform()*5) + 1 // Randomly assign education levels from 1 to 5
	gen agebingroup = round(runiform()*5) + 1 // Randomly assign age bin group from 1 to 5

	
*********************************************
* Generating banking and financial metrics: *
**********************************************

	gen depspread = runiform()*10 // Random deposit spread
	gen ln_debt = ln(1 + runiform()*1e5) // Random log debt
	gen hashome2 = round(runiform()) // Random homeownership status (0 or 1)
	gen ln_housevalue2 = ln(1 + runiform()*1e5) // Random log house value
	gen has_unempl = round(runiform()) // Random unemployment status (0 or 1)
	gen ever_default = round(runiform()) // Random default status (0 or 1)
	gen prate = runiform()*10 // Random prime rate
	gen rprate = prate // Real rate 
	gen depositvol = runiform()*1e5 // Random deposit volumes 
	replace depositvol = 0 if depositvol < 50  // Ensure some deposit volumes are zero
	gen debt = runiform()*1e5 // Random debt volumes
	replace debt = 0 if debt < 50 // Ensure that some debt volumes are zero 
	bys relid (year): gen  number_years_relid_tmp = _N
	egen number_years_relid = max(number_years_relid_tmp), by(relid)
	gen real_assets = runiform()*1e5 // Random real assets values
	gen unemployed = round(runiform()) // Random unemployment status (0 or 1)umb
	gen deprate = runiform()*10 // Random actual deposit rate
	gen ave_dep = runiform()*1e4 // Random average deposit volume
	gen gjeldsrenter = runiform()*1e2 // Random amount of interest paid on loans
	gen loanvol = runiform()*1e4 // Random loan volume
	gen hhi_deposit = runiform() // Random HHI for deposit
	gen hhi_loan = runiform() // Random HHI for loan
	gen w_hhi_dep = runiform() // Random weighted HHI for deposit
	gen w_hhi_loans = runiform() // Random weighted HHI for loans
	gen w_mshare_dep = runiform() // Random weighted market share for deposit
	gen w_mshare_loans = runiform() // Random weighted market share for loans

	
*****************************************	
* Generating household characteristics: *
*****************************************

	gen birthyear = round(1950 + runiform()*50) // Birth years from 1950 to 2000
	gen pop_density = runiform()*1e4 // Random population density
	gen hashome3 = round(runiform()) // Random homeownership status (0 or 1)
	gen loanrate = runiform()*10 // Random loan rate
	gen loanspread_on = runiform()*10 // Random loan spread
	gen parent = round(runiform()) // Random parent status (0 or 1)
	gen retired = round(runiform()) // Random retired status (0 or 1)
	gen ln_inc = ln(1 + runiform()*1e4) // Random log income
	gen wealth = runiform()*1e5 // Random wealth
	gen total_income = runiform()*1e5 // Random income
	gen gross_wealth = wealth // Random wealth
	gen ln_wealth = ln(wealth) // Random log wealth
	gen ln_deposits = ln(depositvol) // Random log deposit volume
	gen old_mshare_deposit = round(runiform()) // Market shares of banks in the old municipality of household
	qui su old_mshare_deposit
	replace old_mshare_deposit = old_mshare_deposit / r(max)
	gen mrkt_share_deposit = round(runiform()) // Current Market shares of banks municipality of household
	qui su mrkt_share_deposit
	replace mrkt_share_deposit = mrkt_share_deposit / r(max)

	
**************************************************	
* Generating variables related to moving places: *
**************************************************

	gen sameplace    = round(runiform()) // Random status (0 or 1) if the household stayed at the same place
	gen withinmovers = round(runiform()) // Random status (0 or 1) if the household moved within the same municipality
	gen acrossmovers = round(runiform()) // Random status (0 or 1) if the household moved to a different municipality

	
***********************	
* Saving the dataset: *
***********************

	save "$path/data/main_data.dta", replace
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
